package org.mark.sell.feign;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.mark.common.entity.FreshFood;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(
    name = "mark-storage",
    path = "/freshFood",
    fallback = StorageFreshFoodFeignClientFallback.class
)
public interface StorageFreshFoodFeignClient {
    
    @GetMapping("/{id}")
    @CircuitBreaker(name = "mark-storage", fallbackMethod = "getByIdFallback")
    FreshFood getById(@PathVariable("id") Integer id);

    default FreshFood getByIdFallback(Integer id, Throwable throwable) {
        // 记录异常信息
        System.err.println("Circuit breaker triggered for id: " + id + ", Exception: " + throwable.getMessage());
        return new StorageFreshFoodFeignClientFallback().getById(id);
    }
} 